Skip to content

Conversation

@GokceGK
Copy link
Contributor

@GokceGK GokceGK commented Dec 16, 2025

Description

Related to STACKITCLI-292

Checklist

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see e.g. here)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

@GokceGK GokceGK requested a review from a team as a code owner December 16, 2025 15:53
@GokceGK GokceGK marked this pull request as draft December 16, 2025 15:54
@GokceGK GokceGK marked this pull request as ready for review January 7, 2026 11:13
@GokceGK GokceGK enabled auto-merge (squash) January 12, 2026 13:43
{
description: "default output",
instance: &logs.LogsInstance{},
model: &inputModel{GlobalFlagModel: &globalflags.GlobalFlagModel{}},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
model: &inputModel{GlobalFlagModel: &globalflags.GlobalFlagModel{}},
model: &inputModel{GlobalFlagModel: nil,

a testcase like this would also be interesting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing a nil pointer issue. Can global flags really be nil? So far I did not see any similar test case. We might need to look into the configuring and parsing the global flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the unit test and nil check in outputResult function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the unit test and nil check also in create command

if err != nil {
return fmt.Errorf("create Logs instance: %w", err)
}
instanceId := *resp.Id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potential nil pointer dereference

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx for the catch, added two more nil checks

instanceId := *resp.Id

// Wait for async operation, if async mode not enabled
if !model.Async {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !model.Async {

Not needed anymore after integration of #1217

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1217 was about the eliminating model.AssumeYes. We still use model.Async check accross cli

}

// Wait for async operation, if async mode not enabled
if !model.Async {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !model.Async {

Not needed anymore after integration of #1217

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. #1217 was about the eliminating model.AssumeYes. We still use model.Async check accross cli

return fmt.Errorf("instance is nil")
}
var outputFormat string
if model.GlobalFlagModel != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now you have a nil pointer dereference if model is nil 😉

I propose the following, just throw an error if the input model / the global flag model is nil:

func outputResult(p *print.Printer, model *inputModel, projectLabel string, instance *logs.LogsInstance) error {
    if instance == nil {
        return fmt.Errorf("instance is nil")
    } else if model == nil || model.GlobalFlagModel == nil {
        return fmt.Errorf("input model is nil")
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, added the check

var outputFormat string
var async bool

if model.GlobalFlagModel != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, added the check :)

@github-actions
Copy link

Merging this branch changes the coverage (1 decrease, 8 increase)

Impacted Packages Coverage Δ 🤖
github.com/stackitcloud/stackit-cli/internal/cmd/beta 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/instance 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/instance/create 42.19% (+42.19%) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/instance/delete 22.92% (+22.92%) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/instance/describe 63.89% (+63.89%) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/instance/list 54.17% (+54.17%) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/instance/update 53.57% (+53.57%) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/config/set 90.51% (+0.21%) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/config/unset 35.25% (-0.05%) 👎
github.com/stackitcloud/stackit-cli/internal/pkg/config 70.04% (+0.11%) 👍
github.com/stackitcloud/stackit-cli/internal/pkg/services/logs/client 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/pkg/services/logs/utils 100.00% (+100.00%) 🌟

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/stackitcloud/stackit-cli/internal/cmd/beta/beta.go 0.00% (ø) 10 (+1) 0 10 (+1)
github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/instance/create/create.go 42.19% (+42.19%) 64 (+64) 27 (+27) 37 (+37) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/instance/delete/delete.go 22.92% (+22.92%) 48 (+48) 11 (+11) 37 (+37) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/instance/describe/describe.go 63.89% (+63.89%) 36 (+36) 23 (+23) 13 (+13) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/instance/instance.go 0.00% (ø) 8 (+8) 0 8 (+8)
github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/instance/list/list.go 54.17% (+54.17%) 48 (+48) 26 (+26) 22 (+22) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/instance/update/update.go 53.57% (+53.57%) 56 (+56) 30 (+30) 26 (+26) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/logs.go 0.00% (ø) 4 (+4) 0 4 (+4)
github.com/stackitcloud/stackit-cli/internal/cmd/config/set/set.go 90.51% (+0.21%) 137 (+3) 124 (+3) 13 👍
github.com/stackitcloud/stackit-cli/internal/cmd/config/unset/unset.go 35.25% (-0.05%) 122 (+3) 43 (+1) 79 (+2) 👎
github.com/stackitcloud/stackit-cli/internal/pkg/config/config.go 90.62% (+0.15%) 64 (+1) 58 (+1) 6 👍
github.com/stackitcloud/stackit-cli/internal/pkg/services/logs/client/client.go 0.00% (ø) 1 (+1) 0 1 (+1)
github.com/stackitcloud/stackit-cli/internal/pkg/services/logs/utils/utils.go 100.00% (+100.00%) 8 (+8) 8 (+8) 0 🌟

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/instance/create/create_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/instance/delete/delete_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/instance/describe/describe_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/instance/list/list_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/beta/logs/instance/update/update_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/config/unset/unset_test.go
  • github.com/stackitcloud/stackit-cli/internal/pkg/services/logs/utils/utils_test.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants